package vd.cloud.com.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import vd.cloud.com.entities.SchoolEntity;
import vd.cloud.com.repositories.SchoolRepository;
import java.util.List;

/**
 * Created by VIET on 2/10/2015.
 */
public class SchoolDAOImpl implements SchoolDAO {

    @Autowired
    private SchoolRepository schoolRepository;

    @Override
    public List<SchoolEntity> findAll() {
        return schoolRepository.findAll();
    }

    @Override
    public List<SchoolEntity> findByNameLike(String name) {
        return schoolRepository.findByNameLike(name);
    }

    @Override
    @Transactional
    public SchoolEntity insert(SchoolEntity schoolEntity) {
        if(schoolEntity.getName().isEmpty()){
            return null;
        }
        return schoolRepository.save(schoolEntity);
    }
}
